﻿var TMPL_TABLE_ID = "tmplTable";
var TMPL_COLGROUP_ID = "tmplColgroup";
var TMPL_HEADER_ID = "tmplHeader";
var TMPL_HEADER_LIVE_ID = "tmplHeader_L";
var TMPL_SUBTITLE_ID = "tmplSubTitle";
var TMPL_LEAGUE_ID = "tmplLeague";
var TMPL_LEAGUE_LIVE_ID = "tmplLeague_L";
var TMPL_LIVE_ID = "tmplLive";
var TMPL_LIVE_MASTER_ID = "tmplLiveMaster";
var TMPL_LIVE_FOOTER_ID = "tmplLiveFooter";
var TMPL_EVENT_ID = "tmplEvent";
var TMPL_EVENT_MASTER_ID = "tmplEventMaster";
var TMPL_EVENT_FOOTER_ID = "tmplEventFooter";
var CLS_UPD = "Odds_Upd";
var CLS_SAME = "Odds_Same";
var CLS_LS_OFF = "displayOff";
var CLS_LS_ON = "displayOn";

function OddsKeeper() {
    var C = this;
    var z = null;
    var t = undefined;
    var s = undefined;
    var x = undefined;
    var v = undefined;
    var u = undefined;
    var f = undefined;
    var e = undefined;
    var d = undefined;
    var y = new Array();
    var b = new Array();
    var c = new Array();
    var B = new Array();
    var w = new Array();
    this.DivBase = 2;
    this.HashHeader = null;
    this.DataTags = null;
    this.EventList = null;
    this.HtmlList = null;
    this.TemplateFrame = null;
    this.DataFrame = null;
    this.TableContainer = null;
    this.BetTypes = null;
    this.SubTitleField;
    this.RegenEverytime = false;
    this.SortType = 0;
    this.SportType;

    function o(P, N) {
        var O = P.document.getElementById(N);
        if (O != null && O.title != "") {
            return P.document.getElementById(O.title)
        }
        return O
    }

    function q(N) {
        var O = "";
        if (N != undefined) {
            O = N.innerHTML;
            O = O.replace(/%7B/g, "{");
            O = O.replace(/%7D/g, "}");
            O = O.replace(/[	\n]/g, "")
        }
        return O
    }

    function p() {
        var N = C.TemplateFrame.document.getElementById(TMPL_TABLE_ID);
        if (N != null) {
            var O = N.parentNode.innerHTML;
            O = O.substring(0, O.indexOf(N.innerHTML));
            O = O.substr(O.lastIndexOf("<"));
            return O
        }
        return "<table>"
    }

    function n() {
        var N = C.TemplateFrame.document.getElementById(TMPL_COLGROUP_ID);
        if (N != null) {
            var O = N.parentNode.innerHTML;
            O = O.substring(0, O.indexOf(N.innerHTML) - 1);
            O = O.substr(O.lastIndexOf("<"));
            return O + N.innerHTML + "</colgroup>"
        }
        return ""
    }

    function k() {
        var N = "";
        if (C.EventList.length == 0) {
            return ""
        } else {
            if (C.EventList[0]["FlagLive"] == "True") {
                if (C.SubTitleField == null) {
                    if (C.TemplateFrame.document.getElementById(TMPL_HEADER_LIVE_ID + "_" + C.SportType) == null) {
                        N = (C.TemplateFrame.document.getElementById(TMPL_HEADER_LIVE_ID) == null) ? C.TemplateFrame.document.getElementById(TMPL_HEADER_ID).innerHTML : C.TemplateFrame.document.getElementById(TMPL_HEADER_LIVE_ID).innerHTML
                    } else {
                        N = C.TemplateFrame.document.getElementById(TMPL_HEADER_LIVE_ID + "_" + C.SportType).innerHTML
                    }
                }
            } else {
                if (C.TemplateFrame.document.getElementById(TMPL_HEADER_ID + "_" + C.SportType) == null) {
                    N = (C.SubTitleField != null) ? "" : C.TemplateFrame.document.getElementById(TMPL_HEADER_ID).innerHTML
                } else {
                    N = (C.SubTitleField != null) ? "" : C.TemplateFrame.document.getElementById(TMPL_HEADER_ID + "_" + C.SportType).innerHTML
                }
            }
        }
        return N
    }

    function m(N) {
        return (C.SubTitleField == null) ? "" : C.TemplateFrame.document.getElementById(TMPL_SUBTITLE_ID + "_" + N).innerHTML
    }

    function l(N) {
        var O = (C.EventList[N]["FlagLive"] == "True") ? s : t;
        O = _replaceTags(C.EventList[N], O);
        if (C.afterNewLeague != null) {
            O = C.afterNewLeague(C.EventList, N, O)
        }
        return O
    }

    function i(N) {
        var O = (C.EventList[N]["FlagLive"] == "True");
        var P;
        if (O) {
            P = _replaceTags(C.EventList[N], x)
        } else {
            P = _replaceTags(C.EventList[N], f)
        } if (C.afterNewEvent != null) {
            P = C.afterNewEvent(C.EventList, N, P, O)
        }
        return P
    }

    function h(N) {
        var O = (C.EventList[N]["FlagLive"] == "True");
        var P;
        if (O) {
            P = _replaceTags(C.EventList[N], v)
        } else {
            P = _replaceTags(C.EventList[N], e)
        } if (C.afterNewEvent != null) {
            P = C.afterNewEvent(C.EventList, N, P, O)
        }
        return P
    }

    function g(N) {
        var O = (C.EventList[N]["FlagLive"] == "True");
        var P;
        if (O) {
            P = _replaceTags(C.EventList[N], u)
        } else {
            P = _replaceTags(C.EventList[N], d)
        } if (C.afterNewEvent != null) {
            P = C.afterNewEvent(C.EventList, N, P, O)
        }
        return P
    }
    this.getTable = function () {
        return z
    };
    this.setTemplate = function (N) {
        this.TemplateFrame = N;
        var O = o(this.TemplateFrame, TMPL_LEAGUE_ID);
        t = q(O);
        t = _formatTemplate(t, "{%", "}");
        var O = o(this.TemplateFrame, TMPL_LEAGUE_LIVE_ID);
        if (O == null) {
            s = t
        } else {
            s = q(O);
            s = _formatTemplate(s, "{%", "}")
        }
        O = o(this.TemplateFrame, TMPL_EVENT_ID + "_" + C.SportType);
        if (O == null) {
            O = o(this.TemplateFrame, TMPL_EVENT_ID)
        }
        f = q(O);
        f = _formatTemplate(f, "{%", "}");
        O = o(this.TemplateFrame, TMPL_LIVE_ID + "_" + C.SportType);
        if (O == null) {
            O = this.TemplateFrame.document.getElementById(TMPL_LIVE_ID);
            if (O == null) {
                x = f
            } else {
                x = q(O);
                x = _formatTemplate(x, "{%", "}")
            }
        } else {
            x = q(O);
            x = _formatTemplate(x, "{%", "}")
        }
        O = o(this.TemplateFrame, TMPL_EVENT_MASTER_ID + "_" + C.SportType);
        if (O == null) {
            O = o(this.TemplateFrame, TMPL_EVENT_MASTER_ID);
            if (O == null) {
                e = f
            } else {
                e = q(O);
                e = _formatTemplate(e, "{%", "}")
            }
        } else {
            e = q(O);
            e = _formatTemplate(e, "{%", "}")
        }
        O = o(this.TemplateFrame, TMPL_EVENT_FOOTER_ID + "_" + C.SportType);
        if (O == null) {
            O = o(this.TemplateFrame, TMPL_EVENT_FOOTER_ID);
            if (O == null) {
                d = e
            } else {
                d = q(O);
                d = _formatTemplate(d, "{%", "}")
            }
        } else {
            d = q(O);
            d = _formatTemplate(d, "{%", "}")
        }
        O = o(this.TemplateFrame, TMPL_LIVE_MASTER_ID + "_" + C.SportType);
        if (O == null) {
            O = this.TemplateFrame.document.getElementById(TMPL_LIVE_MASTER_ID);
            if (O == null) {
                v = x
            } else {
                v = q(O);
                v = _formatTemplate(v, "{%", "}")
            }
        } else {
            v = q(O);
            v = _formatTemplate(v, "{%", "}")
        }
        O = o(this.TemplateFrame, TMPL_LIVE_FOOTER_ID + "_" + C.SportType);
        if (O == null) {
            O = this.TemplateFrame.document.getElementById(TMPL_LIVE_FOOTER_ID);
            if (O == null) {
                u = v
            } else {
                u = q(O);
                u = _formatTemplate(u, "{%", "}")
            }
        } else {
            u = q(O);
            u = _formatTemplate(u, "{%", "}")
        }
    };
    this.setDatas = function (O, P) {
        this.DataTags = P;
        var T = new Array(O.length);
        var R = 0;
        for (var Q = 0; Q < O.length; Q++) {
            var U = _hashData(O[Q], P);
            if (U.LeagueId == "") {
                var V = T[Q - 1];
                U.LeagueId = V.LeagueId;
                U.LeagueName = V.LeagueName
            }
            if (U.MUID == "") {
                var V = T[Q - 1];
                U.MUID = V.MUID;
                U.MatchId = V.MatchId;
                U.MatchCode = V.MatchCode;
                U.HomeName = V.HomeName;
                U.AwayName = V.AwayName;
                U.KickoffTime = V.KickoffTime;
                U.ShowTime = V.ShowTime;
                U.StatsId = V.StatsId;
                U.SportRadar = V.SportRadar;
                U.StreamingId = V.StreamingId;
                U.Favorite = V.Favorite;
                U.TimerSuspend = V.TimerSuspend;
                U.ScoreH = V.ScoreH;
                U.ScoreA = V.ScoreA;
                U.MatchIndex = V.MatchIndex;
                if (typeof (LIVE_SCORE_DEF[C.SportType]) != "undefined") {
                    var N = LIVE_SCORE_DEF[C.SportType];
                    for (var S = 0; S < N.length; S++) {
                        if (typeof (V[N[S]]) != "undefined") {
                            U[N[S]] = V[N[S]]
                        }
                    }
                }
            } else {
                U.MatchIndex = R++
            }
            U.Div = U.MatchIndex % this.DivBase;
            if (this.afterSetData != null) {
                this.afterSetData(Q, U, T)
            }
            T[Q] = U
        }
        this.EventList = T
    };
    this.paintOddsTable = function () {
        var N = new Array(this.EventList.length + 26);
        this.HtmlList = new Array(this.EventList.length);
        N.push(p());
        N.push(n());
        N.push("<THead>");
        N.push(k());
        N.push("</THead><TBody>");
        var U, V, T, Q, W;
        for (var O = 0; O < this.EventList.length; O++) {
            if (this.SubTitleField != null) {
                var X = this.EventList[O][this.SubTitleField];
                if (W != X) {
                    N.push(m(X));
                    W = X
                }
            }
            var R = this.EventList[O]["LeagueId"];
            if (R != U) {
                U = R;
                N.push(l(O))
            }
            var S = this.EventList[O]["MUID"];
            if (O < this.EventList.length - 1) {
                T = this.EventList[O + 1]["MUID"]
            }
            if (V != S) {
                y[S] = O
            }
            if (T != S || O == this.EventList.length - 1) {
                Q = g(O)
            } else {
                if (V == S) {
                    Q = i(O)
                } else {
                    Q = h(O)
                }
            }
            V = S;
            this.HtmlList[O] = Q;
            N.push(Q)
        }
        N.push("</TBody></Table>");
        var P = N.join("");
        this.TableContainer.innerHTML = P;
        z = null;
        z = this.TableContainer.childNodes[0];
        if (this.afterRepaintTable != null) {
            this.afterRepaintTable(z, this.EventList)
        }
    };
    //N - dell
    //P - srtl
    //O - insl
    //R - uLl
    //T- uMl
    //U - uOl
    //Q - uAl
    this.refreshOddsTable = function (N, P, O, R, T, U, Q, S) {
        this.TableContainer.innerHTML = "";
        b = new Array();
        L(T);
        D(R);
        M(U);
        if (this.updateAppendFields != null) {
            this.updateAppendFields(Q, this.EventList, y, b)
        }
        if (S != null) {
            E(S)
        }
        a(N);
        A(P);
        r(O);
        this.regenTableHtml()
    };

    function D(O) {
        for (var P = 0; P < O.length; P++) {
            var X = O[P][0];
            var aa = O[P][1];
            var U = O[P][2];
            var V = O[P][3];
            var W = O[P][4];
            var Z = O[P][5];
            var Y = O[P][6];
            var ab = O[P][7];
            var Q = y[X];
            if (Q == null) {
                continue
            }
            var T = true;
            while ((Q < C.EventList.length) && (C.EventList[Q]["MUID"] == X)) {
                var N = C.EventList[Q];
                N.FlagLive = "True";
                N.ShowTime = aa;
                N.LivePeriod = W;
                N.CsStatus = U;
                N.InjuryTime = V;
                N.TimerSuspend = ab;
                if ((N.ScoreH != Z) || (N.ScoreA != Y)) {
                    N.ScoreH = Z;
                    N.ScoreA = Y;
                    N.Changed_Score = CLS_UPD;
                    if (C.afterScoreChanged != null && T) {
                        C.afterScoreChanged(C.EventList, Q);
                        T = false
                    }
                    B[X] = new Date().getTime()
                } else {
                    var S = B[X];
                    if (S != null) {
                        B[X] = undefined;
                        for (var P = Q; P < C.EventList.length; P++) {
                            var R = C.EventList[P];
                            if (R.MUID != X) {
                                break
                            }
                            R.Changed_Score = ""
                        }
                    }
                    S = w[X];
                    if (S != null) {
                        w[X] = undefined;
                        for (var P = Q; P < C.EventList.length; P++) {
                            var R = C.EventList[P];
                            if (R.MUID != X) {
                                break
                            }
                            switch (C.SportType) {
                                case "2":
                                    R.Changed_Score_1Q = "";
                                    R.Changed_Score_2Q = "";
                                    R.Changed_Score_3Q = "";
                                    R.Changed_Score_4Q = "";
                                    R.Changed_Score_OT = "";
                                    break;
                                case "3":
                                    R.Changed_Score_1Q = "";
                                    R.Changed_Score_2Q = "";
                                    R.Changed_Score_3Q = "";
                                    R.Changed_Score_4Q = "";
                                    R.Changed_Score_OT = "";
                                    R.Changed_DOWN = "";
                                    R.Changed_TOGO = "";
                                    break;
                                case "4":
                                    R.Changed_1s = "";
                                    R.Changed_2s = "";
                                    R.Changed_3s = "";
                                    R.Changed_Score_OT = "";
                                    break;
                                case "7":
                                    R.Changed_1s = "";
                                    R.Changed_Cfm = "";
                                    R.Changed_Pt = "";
                                    break;
                                case "5":
                                case "6":
                                case "9":
                                    R.Changed_1s = "";
                                    R.Changed_2s = "";
                                    R.Changed_3s = "";
                                    R.Changed_4s = "";
                                    R.Changed_5s = "";
                                    R.Changed_Set = "";
                                    R.Changed_Pt = "";
                                    break;
                                case "8":
                                    R.Changed_1s = "";
                                    R.Changed_2s = "";
                                    R.Changed_3s = "";
                                    R.Changed_4s = "";
                                    R.Changed_5s = "";
                                    R.Changed_6s = "";
                                    R.Changed_7s = "";
                                    R.Changed_8s = "";
                                    R.Changed_9s = "";
                                    R.Changed_OT = "";
                                    R.Changed_1b = "";
                                    R.Changed_2b = "";
                                    R.Changed_3b = "";
                                    R.Changed_out = "";
                                    break;
                                default:
                            }
                        }
                    }
                }
                Q++
            }
            b[X] = "live"
        }
    }

    function L(O) {
        for (var P = 0; P < O.length; P++) {
            var R = O[P][0];
            var Q = y[R];
            if (Q == null) {
                continue
            }
            while ((Q < C.EventList.length) && (C.EventList[Q]["MUID"] == R)) {
                var N = C.EventList[Q];
                if (N.FlagLive != "True") {
                    N.ShowTime = O[P][1]
                }
                N.StatsId = O[P][2];
                N.SportRadar = O[P][3];
                N.StreamingId = O[P][4];
                N.Favorite = O[P][5];
                N.HomeName = O[P][6];
                N.AwayName = O[P][7];
                N.KickoffTime = O[P][8];
                Q++
            }
            b[R] = "Match"
        }
    }

    function M(N) {
        for (var W in c) {
            var T = y[W];
            if (T == null) {
                continue
            }
            while ((T < C.EventList.length) && (C.EventList[T]["MUID"] == W)) {
                for (var Q = 0; Q < C.BetTypes.length; Q++) {
                    C.EventList[T]["Changed_" + C.BetTypes[Q]] = ""
                }
                b[W] = "oddsClear";
                T++
            }
        }
        c = new Array();
        for (var Q = 0; Q < N.length; Q++) {
            var W = N[Q][0];
            var R = N[Q][1];
            var X = N[Q][2];
            var T = y[W];
            var P = false;
            var U = _hashData(N[Q], ODDS_DEF[R]);
            while ((T < C.EventList.length) && (C.EventList[T]["MUID"] == W)) {
                if (C.EventList[T]["OddsId_" + R] == X) {
                    P = true;
                    b[C.EventList[T]["MUID"]] = "oddsNew";
                    var S = 0;
                    var O = false;
                    for (var V in U) {
                        if ((S >= 3) && (C.EventList[T][V] != U[V])) {
                            if (R == 905) {
                                C.EventList[T][V.replace("Odds", "Changed")] = CLS_UPD
                            }
                            C.EventList[T][V] = U[V];
                            O = true
                        } else {
                            if (S >= 3 && R == 905) {
                                C.EventList[T][V.replace("Odds", "Changed")] = ""
                            }
                        }
                        S++
                    }
                    if (O) {
                        C.EventList[T]["Changed_" + R] = CLS_UPD;
                        c[C.EventList[T]["MUID"]] = 1
                    }
                    break
                }
                T++
            }
        }
    }

    function H(O) {
        J(O);
        for (var Q = 0; Q < O.length; Q++) {
            var S = O[Q][0];
            var R = y[S];
            if (R == null) {
                continue
            }
            var P = false;
            while ((R < C.EventList.length) && (C.EventList[R]["MUID"] == S)) {
                var N = C.EventList[R];
                P = false;
                if (N.DOWN != O[Q][14]) {
                    N.Changed_DOWN = CLS_UPD;
                    P = true
                }
                if (N.TOGO != O[Q][15]) {
                    N.Changed_TOGO = CLS_UPD;
                    P = true
                }
                if (P) {
                    w[S] = new Date().getTime()
                }
                R++
            }
        }
    }

    function J(O) {
        for (var Q = 0; Q < O.length; Q++) {
            var S = O[Q][0];
            var R = y[S];
            if (R == null) {
                continue
            }
            var P = false;
            while ((R < C.EventList.length) && (C.EventList[R]["MUID"] == S)) {
                var N = C.EventList[R];
                P = false;
                if (N.H1Q != O[Q][3] || N.A1Q != O[Q][7]) {
                    N.Changed_Score_1Q = CLS_UPD;
                    P = true
                }
                if (N.H2Q != O[Q][4] || N.A2Q != O[Q][8]) {
                    N.Changed_Score_2Q = CLS_UPD;
                    P = true
                }
                if (N.H3Q != O[Q][5] || N.A3Q != O[Q][9]) {
                    N.Changed_Score_3Q = CLS_UPD;
                    P = true
                }
                if (N.H4Q != O[Q][6] || N.A4Q != O[Q][10]) {
                    N.Changed_Score_4Q = CLS_UPD;
                    P = true
                }
                if (N.HOT != O[Q][11] || N.AOT != O[Q][12]) {
                    N.Changed_Score_OT = CLS_UPD;
                    P = true
                }
                if (P) {
                    w[S] = new Date().getTime()
                }
                R++
            }
        }
    }

    function K(O) {
        for (var Q = 0; Q < O.length; Q++) {
            var S = O[Q][0];
            var R = y[S];
            if (R == null) {
                continue
            }
            var P = false;
            while ((R < C.EventList.length) && (C.EventList[R]["MUID"] == S)) {
                var N = C.EventList[R];
                P = false;
                if (N.HS != O[Q][15] || N.AS != O[Q][16]) {
                    N.Changed_Set = CLS_UPD;
                    P = true
                }
                if (parseInt(O[Q][2], 10) > 0) {
                    if (N["H" + O[Q][2] + "S"] != O[Q][parseInt(O[Q][2], 10) + 2] || N["A" + O[Q][2] + "S"] != O[Q][parseInt(O[Q][2], 10) + 7]) {
                        N["Changed_" + O[Q][2] + "s"] = CLS_UPD;
                        P = true
                    }
                }
                if (N.HPT != O[Q][13] || N.APT != O[Q][14]) {
                    if (O[Q][13] == "0" && O[Q][14] == "0") {
                        N.Changed_Pt = ""
                    } else {
                        N.Changed_Pt = CLS_UPD
                    }
                    P = true
                }
                if (P) {
                    w[S] = new Date().getTime()
                }
                R++
            }
        }
    }

    function G(O) {
        for (var Q = 0; Q < O.length; Q++) {
            var S = O[Q][0];
            var R = y[S];
            if (R == null) {
                continue
            }
            var P = false;
            while ((R < C.EventList.length) && (C.EventList[R]["MUID"] == S)) {
                var N = C.EventList[R];
                P = false;
                if (N.HFM != O[Q][2] || N.AFM != O[Q][3]) {
                    N.Changed_1s = CLS_UPD;
                    P = true
                }
                if (N.CFM != O[Q][4]) {
                    N.Changed_Cfm = CLS_UPD;
                    P = true
                }
                if (N.HPT != O[Q][5] || N.APT != O[Q][6]) {
                    if (O[Q][5] == "0" && O[Q][6] == "0") {
                        N.Changed_Pt = ""
                    } else {
                        N.Changed_Pt = CLS_UPD
                    }
                    P = true
                }
                if (P) {
                    w[S] = new Date().getTime()
                }
                R++
            }
        }
    }

    function I(O) {
        for (var Q = 0; Q < O.length; Q++) {
            var S = O[Q][0];
            var R = y[S];
            if (R == null) {
                continue
            }
            var P = false;
            while ((R < C.EventList.length) && (C.EventList[R]["MUID"] == S)) {
                var N = C.EventList[R];
                P = false;
                if (parseInt(O[Q][2], 10) > 0) {
                    if (N["H" + O[Q][2] + "S"] != O[Q][parseInt(O[Q][2], 10) + 2] || N["A" + O[Q][2] + "S"] != O[Q][parseInt(O[Q][2], 10) + 5]) {
                        N["Changed_" + O[Q][2] + "s"] = CLS_UPD;
                        P = true
                    }
                }
                if (N.HOT != O[Q][9] || N.AOT != O[Q][10]) {
                    N.Changed_Score_OT = CLS_UPD;
                    P = true
                }
                if (P) {
                    w[S] = new Date().getTime()
                }
                R++
            }
        }
    }

    function F(O) {
        for (var Q = 0; Q < O.length; Q++) {
            var S = O[Q][0];
            var R = y[S];
            if (R == null) {
                continue
            }
            var P = false;
            while ((R < C.EventList.length) && (C.EventList[R]["MUID"] == S)) {
                var N = C.EventList[R];
                P = false;
                for (j = 1; j <= 9; j++) {
                    if (N["H" + j + "S"] != O[Q][j + 2] || N["A" + j + "S"] != O[Q][j + 11]) {
                        N["Changed_" + j + "s"] = CLS_UPD;
                        P = true
                    }
                }
                if (N.HOT != O[Q][21] || N.AOT != O[Q][22]) {
                    N.Changed_OT = CLS_UPD;
                    P = true
                }
                if (N.Battle != O[Q][22]) {
                    if (O[Q][24] == "0" && O[Q][25] == "0" && O[Q][26] == "0") {
                        for (j = 1; j <= 3; j++) {
                            N["Changed_" + j + "b"] = ""
                        }
                    } else {
                        for (j = 1; j <= 3; j++) {
                            if (N["B" + j] != O[Q][23 + j]) {
                                N["Changed_" + j + "b"] = CLS_UPD;
                                P = true
                            }
                        }
                    } if (O[Q][27] == "0") {
                        N.Changed_out = ""
                    } else {
                        if (N.Out != O[Q][27]) {
                            N.Changed_out = CLS_UPD;
                            P = true
                        }
                    }
                }
                if (P) {
                    w[S] = new Date().getTime()
                }
                R++
            }
        }
    }

    function E(P) {
        switch (C.SportType) {
            case "2":
                J(P);
                break;
            case "3":
                H(P);
                break;
            case "4":
                I(P);
                break;
            case "7":
                G(P);
                break;
            case "5":
            case "6":
            case "9":
                K(P);
                break;
            case "8":
                F(P);
                break;
            default:
        }
        var O = LIVE_SCORE_DEF[C.SportType];
        if (O instanceof Array) {
            for (var Q = 0; Q < P.length; Q++) {
                var T = P[Q][0];
                var R = y[T];
                if (R == null) {
                    continue
                }
                while ((R < C.EventList.length) && (C.EventList[R]["MUID"] == T)) {
                    var N = C.EventList[R];
                    for (var S = 1; S < O.length; S++) {
                        N[O[S]] = P[Q][S]
                    }
                    R++
                }
                b[T] = "LiveScore"
            }
        }
    }

    function a(N) {
        for (var O = 0; O < N.length; O++) {
            var S = N[O];
            var P = y[S];
            var Q = P + 1;
            while (Q < C.EventList.length) {
                if (C.EventList[Q]["MUID"] != S) {
                    Q--;
                    break
                }
                Q++
            }
            C.EventList = arrayRemove(C.EventList, P, Q);
            C.HtmlList = arrayRemove(C.HtmlList, P, Q);
            for (var R = C.EventList.length - 1; R >= P; R--) {
                y[C.EventList[R]["MUID"]] = R
            }
            B[S] = null;
            w[S] = null
        }
    }

    function r(Q) {
        var T, S;
        for (var O = 0; O < Q.length; O++) {
            S = _hashData(Q[O], C.DataTags);
            if (S.LeagueId == "") {
                S.LeagueId = T.LeagueId;
                S.LeagueName = T.LeagueName
            }
            if (S.MUID == "") {
                S.MUID = T.MUID;
                S.MatchId = T.MatchId;
                S.MatchCode = T.MatchCode;
                S.HomeName = T.HomeName;
                S.AwayName = T.AwayName;
                S.KickoffTime = T.KickoffTime;
                S.ShowTime = T.ShowTime;
                S.StatsId = T.StatsId;
                S.SportRadar = T.SportRadar;
                S.StreamingId = T.StreamingId;
                S.Favorite = T.Favorite;
                S.ScoreH = T.ScoreH;
                S.ScoreA = T.ScoreA;
                S.TimerSuspend = T.TimerSuspend;
                if (typeof (LIVE_SCORE_DEF[C.SportType]) != "undefined") {
                    var N = LIVE_SCORE_DEF[C.SportType];
                    for (var R = 0; R < N.length; R++) {
                        if (typeof (T[N[R]]) != "undefined") {
                            S[N[R]] = T[N[R]]
                        }
                    }
                }
            }
            var P;
            if (C.SortType == 1) {
                P = C.findIndex("KickoffTime", S.KickoffTime);
                P = C.adjustIndex1(P, "KickoffTime", S.KickoffTime, S.MatchCode)
            } else {
                P = C.findIndex("MatchCode", S.MatchCode);
                P = C.adjustIndex0(P, "MatchCode", S.MatchCode, S.MUID)
            }
            T = S;
            C.EventList = arrayInsert(C.EventList, P, new Array(S));
            C.HtmlList = arrayInsert(C.HtmlList, P, new Array(""));
            b[S.MUID] = "ins"
        }
    }

    function A(N) {
        for (var W in N) {
            b[W] = "srt";
            var X = N[W];
            var T = y[W];
            var U = T + 1;
            while (U < C.EventList.length) {
                if (C.EventList[U]["MUID"] != W) {
                    U--;
                    break
                }
                U++
            }
            var V = C.EventList[T]["MatchCode"];
            var O = C.EventList.slice(T, U + 1);
            var P = C.HtmlList.slice(T, U + 1);
            var Y = (C.SortType == 1) ? "KickoffTime" : "MatchCode";
            for (var Q = 0; Q < O.length; Q++) {
                O[Q][Y] = X
            }
            C.EventList = arrayRemove(C.EventList, T, U);
            C.HtmlList = arrayRemove(C.HtmlList, T, U);
            var S;
            if (C.SortType == 1) {
                S = C.findIndex("KickoffTime", X);
                S = C.adjustIndex1(S, "KickoffTime", X, V)
            } else {
                S = C.findIndex("MatchCode", X);
                S = C.adjustIndex0(S, "MatchCode", X, W)
            }
            C.EventList = arrayInsert(C.EventList, S, O);
            C.HtmlList = arrayInsert(C.HtmlList, S, P);
            var R = (T < S) ? T : S;
            for (var Q = C.EventList.length - 1; Q >= R; Q--) {
                y[C.EventList[Q]["MUID"]] = Q
            }
        }
    }
    this.findIndex = function (O, S) {
        var P = 0;
        var R = this.EventList.length - 1;
        var Q;
        if (this.EventList.length == 0) {
            return 0
        } else {
            if (S >= this.EventList[R][O]) {
                return R + 1
            } else {
                if (S < this.EventList[P][O]) {
                    return P
                }
            }
        }
        while (P <= R) {
            Q = Math.ceil((P + R) / 2);
            var N = this.EventList[Q][O];
            if (N < S) {
                P = Q + 1
            } else {
                if (N > S) {
                    R = Q - 1
                } else {
                    for (Q = Q + 1; Q < this.EventList.length; Q++) {
                        if (this.EventList[Q][O] != S) {
                            return Q
                        }
                    }
                }
            }
        }
        if (Q + 1 >= this.EventList.length) {
            Q = this.EventList.length - 2
        }
        for (Q = Q + 1; Q >= 0; Q--) {
            if (this.EventList[Q][O] <= S) {
                return Q + 1
            }
        }
        return 0
    };
    this.adjustIndex0 = function (O, P, Q) {
        for (var N = O - 1;
            (N >= 0) && (this.EventList[N]["MatchCode"] == P) ; N--) {
            if (this.EventList[N]["MUID"] >= Q) {
                return N + 1
            }
        }
        return O
    };
    this.adjustIndex1 = function (O, P, Q) {
        for (var N = O - 1;
            (N >= 0) && (this.EventList[N]["KickoffTime"] == P) ; N--) {
            if (this.EventList[N]["MatchCode"] >= Q) {
                return N + 1
            }
        }
        return O
    };
    this.adjustIndex1st = function (P, N, S, R) {
        var O;
        for (O = P - 1;
            (O >= 0) && (this.EventList[O][N] == S) ; O--) {
            if (this.EventList[O]["MUID"] == R) {
                break
            }
        }
        var Q;
        for (Q = O;
            (Q >= 0) && (this.EventList[Q][N] == S) ; Q--) {
            if (this.EventList[Q]["MUID"] != R) {
                break
            }
        }
        return Q + 1
    };
    this.regenTableHtml = function () {
        y = new Array();
        var N = new Array();
        N.push(p());
        N.push(n());
        N.push("<THead>" + k() + "</THead><TBody>");
        var S, V, W, X;
        var Q = "-1";
        for (var O = 0; O < this.EventList.length; O++) {
            if (this.SubTitleField != null) {
                var Y = this.EventList[O][this.SubTitleField];
                if (X != Y) {
                    N.push(m(Y));
                    X = Y
                }
            }
            var R = this.EventList[O];
            S = R.LeagueId;
            if (S != V) {
                V = S;
                N.push(l(O))
            }
            var T = this.EventList[O]["MUID"];
            var U;
            if (O < this.EventList.length - 1) {
                U = this.EventList[O + 1]["MUID"]
            }
            if ((W != T)) {
                y[T] = O;
                R.MatchIndex = ++Q
            } else {
                R.MatchIndex = Q
            }
            var P = R.MatchIndex % this.DivBase;
            if ((C.RegenEverytime) || (b[R.MUID] != null) || (R.Div != P)) {
                R.Div = P;
                if (U != T || O == this.EventList.length - 1) {
                    this.HtmlList[O] = g(O)
                } else {
                    this.HtmlList[O] = (W != T) ? h(O) : i(O)
                }
            }
            W = T;
            N.push(this.HtmlList[O])
        }
        N.push("</TBody></Table>");
        this.TableContainer.innerHTML = N.join("");
        z = null;
        z = this.TableContainer.childNodes[0];
        if (this.afterRepaintTable != null) {
            this.afterRepaintTable(z, this.EventList)
        }
    }
}

function _replaceTags(a, c) {
    var b = new Array(c.length * 2 - 1);
    b[0] = c[0];
    var e;
    for (var d = 1; d < c.length; d++) {
        e = d * 2;
        b[e - 1] = a[c[d][0]];
        b[e] = c[d][1]
    }
    return (b.join("")).replace(/td>\s+<td/g, "td><td")
}

function replaceTags(a, b) {
    return _replaceTags(a, _formatTemplate(b, "{%", "}"))
}

function _formatTemplate(f, d, e) {
    var a = f.split(d);
    for (var b = 1; b < a.length; b++) {
        var c = a[b].indexOf(e);
        a[b] = [a[b].substr(0, c), a[b].substr(c + 1, a[b].length - c)]
    }
    return a
}

function _hashData(a, b) {
    var e = new Array();
    var c = Math.min(a.length, b.length);
    for (var d = 0; d < c; d++) {
        e[b[d]] = a[d]
    }
    return e
}

function arrayRemove(a, d, e) {
    if (e == null) {
        e = d
    }
    if (d > e) {
        return a.concat([])
    }
    if (d < 0) {
        d = 0
    }
    if (e >= a.length) {
        e = a.length - 1
    }
    var b = a.slice(0, d);
    var c = a.slice(e + 1);
    return b.concat(c)
}

function arrayInsert(a, e, b) {
    if (e <= 0) {
        return b.concat(a)
    } else {
        if (e >= a.length) {
            return a.concat(b)
        } else {
            var c = a.slice(0, e);
            var d = a.slice(e);
            c = c.concat(b);
            return c.concat(d)
        }
    }
}

function SimpleOddsKeeper() {
    this.TableContainer = null;
    this.DivTmpl = null;
    this.newHash = new Array();
    this.oHash = new Array();
    this.MUID = null;
    this.MatchId = null;
    this.isParlay = "false";
    this.Market = "";
    this.setDatas = function (c, d) {
        this.oHash = a(c, d, this.oHash)
    };

    function a(c, d, g) {
        var e = Math.min(c.length, d.length);
        for (var f = 0; f < e; f++) {
            g[d[f]] = c[f]
        }
        return g
    }

    function b(c, e) {
        var d = new Array(e.length * 2 - 1);
        d[0] = e[0];
        var g;
        for (var f = 1; f < e.length; f++) {
            g = f * 2;
            d[g - 1] = c[e[f][0]];
            d[g] = e[f][1]
        }
        return (d.join(""))
    }
    this.AppendOddsTable = function () {
        var c;
        var d = this.DivTmpl;
        if (this.oHash != null) {
            c = _formatTemplate(d, "{%", "}");
            d = b(this.oHash, c)
        }
        if (this.newHash != null) {
            c = _formatTemplate(d, "{@", "}");
            d = b(this.newHash, c)
        }
        this.TableContainer.innerHTML = this.TableContainer.innerHTML + d
    };
    this.paintOddsTable = function () {
        var c;
        this.TableContainer.innerHTML = this.DivTmpl;
        if (this.oHash != null) {
            c = _formatTemplate(this.TableContainer.innerHTML, "{%", "}");
            this.TableContainer.innerHTML = b(this.oHash, c)
        }
        if (this.newHash != null) {
            c = _formatTemplate(this.TableContainer.innerHTML, "{@", "}");
            this.TableContainer.innerHTML = b(this.newHash, c)
        }
    };
    this.updateOdds = function (g, f, c) {
        for (var d = 0; d < c.length; d++) {
            for (var e = 1; e < MultiSportODDS_DEF[parseInt(c[d], 10)].length; e++) {
                if (g[MultiSportODDS_DEF[parseInt(c[d], 10)][e]] != f[MultiSportODDS_DEF[parseInt(c[d], 10)][e]]) {
                    f["Changed_" + c[d]] = CLS_UPD;
                    break
                } else {
                    f["Changed_" + c[d]] = ""
                }
            }
        }
        return f
    }
};